<?php

/**
 * Exchange create by manager
 *
 * @package    letsManager
 * @subpackage form
 * @author     Jerome Fouilloy
 * @version    SVN: $Rev$
 */
abstract class PluginLetsExchangeForm extends BaseLetsExchangeForm
{
  public function setup()
  {
    parent::setup();

    $this->useFields(array('name','category_id','amount'));

    $user = sfContext::getInstance()->getUser();
    $asso_id = $user->getAssociationId();
    // get members list enabled and ordered and exclude the current user
    if($this->isNew())
    {
      $this->widgetSchema['creditor_id'] = new letsWidgetFormMemberSelect();
      $this->validatorSchema['creditor_id'] = new sfValidatorDoctrineChoice(array('model' => 'Member'));
      
      // if can't add exchange for other he can add only for debitor association
      if($user->hasPermission(LetsManagerRights::ADD_EXCHANGE_OTHERS))
      {
        $this->widgetSchema['debitor_id'] = new letsWidgetFormMemberSelect();
        $this->validatorSchema['debitor_id'] = new sfValidatorDoctrineChoice(array('model' => 'Member'));
        
        $this->widgetSchema['state_validated'] = new sfWidgetFormInputCheckbox(array(
        	'value_attribute_value' => 'true'
        ));
        $this->validatorSchema['state_validated'] = new sfValidatorBoolean();
      }
      $this->widgetSchema['date_exchange'] = new pwWidgetFormJQueryDatePicker(date('Y')-1,date('Y'),false);
      $this->setDefault('date_exchange',time());
      $this->validatorSchema['date_exchange'] = new sfValidatorDate();
      
    }

    $this->widgetSchema['name']->setAttribute('class', 'formInputLarge');
    $this->widgetSchema['amount']->setAttribute('class', 'formInputShort');
    $this->validatorSchema['amount']->setOption('min',1);
    $this->widgetSchema->setLabels(array(
      'creditor_id'   => 'Créditeur',
      'debitor_id'   => 'Débiteur',
      'name'   => 'Service rendu',
      'category_id' => 'Dans la catégorie',
      'amount' => 'Montant',
      'date_exchange' => "Date de l'échange",
      'state_validated' => 'Echange validé<br/>par les 2 adhérents'
    ));
    
      /* $this->validatorSchema['debitor_id'] = new sfValidatorAnd(array(
       $this->validatorSchema['debitor_id'],
       new sfValidatorSchemaCompare('debitor_id',sfValidatorSchemaCompare::NOT_EQUAL,'creditor_id',
       array(),array('invalid'=>'Doit être différent du créditeur'));
       ));*/

      /*	$this->widgetSchema->setHelps(array(
       'creditor_id' => 'Créditeur de l\'échange',
       'debitor_id'   => 'Debiteur de l\'échange',
       'service_id'   => 'Service rendu pour l\'échange',
       'note_id'   => 'Appréciation de l\'échange',
       'amount' => 'Montant de l\'échange'
       ));*/
  }
}
